package com.zhongjian.technologycal.mall.activity.healthily.activity;

import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;

import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.base.BaseActivity;
import com.zhongjian.technologycal.mall.utils.StatusBarUtil;

import butterknife.BindView;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * Created by wei on 2017/12/15.
 */

public class IjkVideoPlayerActivity extends BaseActivity {
    @BindView(R.id.custom_videoplayer_standard)
    JCVideoPlayerStandard jcVideoPlayerStandard;

    JCVideoPlayer.JCAutoFullscreenListener sensorEventListener;
    SensorManager sensorManager;

    @Override
    protected void beforeInit() {
        super.beforeInit();
//        StatusBarUtil.setColorNoTranslucent(this, getResources().getColor(R.color.white));
//        StatusBarUtil.setMiuiStatusBarDarkMode(this, true);

    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        // http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4
        jcVideoPlayerStandard.setUp("http://www.iqiyi.com/w_19rtw2drlx.html?src=sharemodclk131212"
                , JCVideoPlayerStandard.SCREEN_LAYOUT_LIST, "杭州众健网络科技有限公司企业宣传片");
//        jcVideoPlayerStandard.thumbImageView.setThumbInCustomProject("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640");

        sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        sensorEventListener = new JCVideoPlayer.JCAutoFullscreenListener();
    }

    @Override
    public void initPresenter() {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_ijk_videoplayer;
    }

    @Override
    public void onBackPressed() {
        if (JCVideoPlayer.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onResume() {
        super.onResume();
        Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
        sensorManager.registerListener(sensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JCVideoPlayer.releaseAllVideos();
        sensorManager.unregisterListener(sensorEventListener);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        JCVideoPlayer.releaseAllVideos();
    }


}
